package cn.bonoon.kernel.web.handlers;

import cn.bonoon.kernel.events.DialogEvent;
import cn.bonoon.kernel.web.controllers.BaseButtonResolver;
import cn.bonoon.kernel.web.models.DialogModel;

/**
 * <pre>
 * 可以自己定义弹出的对话框的内容
 * 
 * 子类可以：
 * 1. 重写{@link #initRegister()}方法，添加或修改弹出对话框的界面样式、按钮、toolbar等
 * 2. 重写{@link #internalExecute(DialogModel, DialogEvent)}方法，在打开对话框时进行界面的初始化赋值
 * 3. 调用{@link #addButton(DialogOperateHandler)}方法添加对话框的按钮
 * 
 * 如果是对某一条或多条记录进行编辑修改，则可以通过{@link DialogEvent}取得相应的参数
 * </pre>
 * 
 * @author jackson
 *
 */
public abstract class AbstractDialogSimpleHandler extends AbstractDialogHandler{
	protected final StringBuilder html, dlgAttrs;
	protected AbstractDialogSimpleHandler(String viewName, HandlerRegister register) throws Exception {
		super(null, register);
		this.viewName = viewName;
		this.html = new StringBuilder();
//		this.block = new StringBuilder();
		this.dlgAttrs = new StringBuilder();
		this.dialogMaster = "layout-dialog-simple.vm";
	}

	@Override
	public BaseButtonResolver register(BaseButtonResolver resolver) throws Exception {
		parse(html, block, dlgAttrs);
		return super.register(resolver);
	}
	
	@Override
	protected void internalExecute(DialogModel model, DialogEvent event) throws Exception {
		model.addBlock(block);
		model.addDialogAttrs(dlgAttrs);
		model.addHtml(html);
	}
}
